﻿using MusicStore.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;

namespace MusicStore.Controllers
{
    public class TemporaryController : Controller
    {
        private MusicStoreDB db = new MusicStoreDB();
        public ActionResult Index()
        {
            return View();
        }
        //public ActionResult Seacrh(string s)
        //{

        //    var albums = db.Albums.Where(x => x.Title.Contains(s));
        //    return View(albums);
        //}
        public ActionResult Seacrh(string s)
        {

            var albums = db.Albums
                .Include("Artist")
                 .Include("Genre")
                 .Where(x => x.Title.Contains(s) || x.Genre.Name.Contains(s) || x.Artist.Name.Contains(s));
            return View(albums);
        }
        public ActionResult Details(int id)
        {
            Album album = db.Albums.Find(id);
            db.Albums.Remove(album);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        public ActionResult Delete(int? id)
        {
            if(id==null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            var album = db.Albums.Find(id);
            if(album==null)
            {
                return HttpNotFound();
            }
            return View(album);
        }
        [HttpPost ]
        [ValidateAntiForgeryToken]
        public ActionResult Delete(int id)
        {
            Album album = db.Albums.Find(id);
            db.Albums.Remove(album);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
    }
}